/*
 * SiFiSy - A File System Simulator
 * Copyright (C) 2010  SevenSoft
 *
 * This file is part of SiFiSy.
 *
 * SiFiSy is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SiFiSy is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SiFiSy.  If not, see <http://www.gnu.org/licenses/>.
 */

package sifisy.newgui;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import sifisy.connections.PreferencesManager;
import sifisy.core.Model;

/**
 * @author Giuseppe Biolo
 * @version %I%, %G%
 * @createData 27/05/2010
 */
public class PreferencesWizard extends JFrame {
    private PreferencesManager preferencesManager;
    private JLabel language_l;
    private JLabel wizard_l;
    private JLabel schemaPath_l;
    private JLabel guiTanslatePath_l;
    private JLabel getHelpPath_l;
    private JLabel defaultSimulationPath_l;
    private JComboBox language_c;
    private JComboBox wizard_c;
    private JTextField schemaPath_t;
    private JTextField guiTranslatePath_t;
    private JTextField getHelpPath_t;
    private JTextField defaultSimulationPath_t;
    private JButton ok;
    private JButton back;
    private JButton extra;

    private void initComponents() {
        language_l = new JLabel(Model.translate("language"));
        wizard_l = new JLabel(Model.translate("wizard"));
        schemaPath_l = new JLabel(Model.translate("schemaPath"));
        guiTanslatePath_l = new JLabel(Model.translate("languagePath"));
        getHelpPath_l = new JLabel(Model.translate("helpPath"));
        defaultSimulationPath_l = new JLabel(Model.translate("defaultPath"));
        language_c = new JComboBox();
        language_c.addItem("it");
        language_c.addItem("en");
        wizard_c = new JComboBox();
        wizard_c.addItem(Model.translate("yes"));
        wizard_c.addItem("No");
        schemaPath_t = new JTextField(15);
        guiTranslatePath_t = new JTextField(15);
        getHelpPath_t = new JTextField(15);
        defaultSimulationPath_t = new JTextField(15);
        ok = new JButton("OK");
        back = new JButton(Model.translate("back"));
        extra = new JButton(Model.translate("advanced"));

        ok.addMouseListener(preferencesManager.new ChangeSetup());

        back.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                (PreferencesWizard.this).dispose();
            }
        });
    }

    private void loadSetupValues() {
        language_c.setSelectedItem(new String(Model.getLanguage()));
        if(Model.getShowWizard().equals("true")) {
            wizard_c.setSelectedIndex(0);
        }
        else {
            wizard_c.setSelectedIndex(1);
        }
        schemaPath_t.setText(Model.getSchemaPath());
        guiTranslatePath_t.setText(Model.getGuiTranslatePath());
        getHelpPath_t.setText("??");
        defaultSimulationPath_t.setText(Model.getDefaultSimulationPath());
    }

    public PreferencesWizard() {
        super(Model.translate("sifisyConfig"));

        preferencesManager = new PreferencesManager(this);

        initComponents();

        JPanel languageLabel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        languageLabel.add(language_l);

        JPanel languageCombo = new JPanel(new FlowLayout(FlowLayout.LEFT));
        languageCombo.add(language_c);

        JPanel wizardLabel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        wizardLabel.add(wizard_l);

        JPanel wizardCombo = new JPanel(new FlowLayout(FlowLayout.LEFT));
        wizardCombo.add(wizard_c);

        JPanel schemaPathLabel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        schemaPathLabel.add(schemaPath_l);

        JPanel schemaPathText = new JPanel(new FlowLayout(FlowLayout.LEFT));
        schemaPathText.add(schemaPath_t);

        JPanel guiTanslatePathLabel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        guiTanslatePathLabel.add(guiTanslatePath_l);

        JPanel guiTranslatePathText = new JPanel(new FlowLayout(FlowLayout.LEFT));
        guiTranslatePathText.add(guiTranslatePath_t);

        JPanel getHelpPathLabel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        getHelpPathLabel.add(getHelpPath_l);

        JPanel getHelpPathText = new JPanel(new FlowLayout(FlowLayout.LEFT));
        getHelpPathText.add(getHelpPath_t);

        JPanel defaultSimulationPathLabel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        defaultSimulationPathLabel.add(defaultSimulationPath_l);

        JPanel defaultSimulationPathText = new JPanel(new FlowLayout(FlowLayout.LEFT));
        defaultSimulationPathText.add(defaultSimulationPath_t);

        JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        buttonsPanel.add(back);
        buttonsPanel.add(ok);

        JPanel standardPreferences = new JPanel(new GridLayout(2,2));
        standardPreferences.add(languageLabel);
        standardPreferences.add(languageCombo);
        standardPreferences.add(wizardLabel);
        standardPreferences.add(wizardCombo);

        JPanel hackerPreferences = new JPanel(new GridLayout(4,2));
        hackerPreferences.add(schemaPathLabel);
        hackerPreferences.add(schemaPathText);
        hackerPreferences.add(guiTanslatePathLabel);
        hackerPreferences.add(guiTranslatePathText);
        hackerPreferences.add(getHelpPathLabel);
        hackerPreferences.add(getHelpPathText);
        hackerPreferences.add(defaultSimulationPathLabel);
        hackerPreferences.add(defaultSimulationPathText);

        JTabbedPane mainPanel = new JTabbedPane();
        mainPanel.add("Standard",standardPreferences);
        mainPanel.add(Model.translate("nerd"),hackerPreferences);

        setLayout(new BorderLayout());

        add(mainPanel,BorderLayout.CENTER);
        add(buttonsPanel,BorderLayout.SOUTH);

        setSize(375,250);

        loadSetupValues();

        setVisible(true);
    }

    public JComboBox getLanguage_c() {
        return language_c;
    }

    public JTextField getDefaultSimulationPath_t() {
        return defaultSimulationPath_t;
    }

    public JTextField getSchemaPath_t() {
        return schemaPath_t;
    }

    public JComboBox getWizard_c() {
        return wizard_c;
    }

    public JTextField getGuiTranslatePath_t() {
        return guiTranslatePath_t;
    }
}
